package com.forum.Service.Impl;

import com.forum.Entity.Like;
import com.forum.Mapper.LikeMapper;
import com.forum.Service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LikeServiceImpl implements LikeService {
    @Autowired
    private LikeMapper likeMapper;
    @Override
    public List<Like> getLikesList(String userId) {
        return likeMapper.getLikesList(userId);
    }

    @Override
    public void addLike(Like like) {
        like.setLikeId(makeId());
        likeMapper.addLike(like);
    }

    @Override
    public void deleteLike(String userId, String targetId) {
        likeMapper.deleteLike(userId, targetId);
    }

    @Override
    public void deletePostLike(String postId) {
        likeMapper.deleteLikeByTargetId(postId);
    }

    @Override
    public void deleteCommentLike(String commentId) {
        likeMapper.deleteLikeByTargetId(commentId);
    }

    private String makeId() {
        return "L" + System.currentTimeMillis();
    }
}
